using DryIoc;
using Quartz.Spi;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism.Ioc;

namespace AYE.BaseFramework.Manager;

public class DryIocJobFactory : IJobFactory
{
    private readonly IContainer _container;

    public DryIocJobFactory(IContainer container)
    {
        _container = container;
    }

    public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
    {
        try
        {
            var jobType = bundle.JobDetail.JobType;
            return (IJob)_container.Resolve(jobType);
        }
        catch (Exception ex)
        {
            throw new SchedulerException($"Problem instantiating job: {bundle.JobDetail.JobType.FullName}", ex);
        }
    }

    /// <summary>
    /// job的 清除操作
    /// </summary>
    /// <param name="job"></param>
    public void ReturnJob(IJob job)
    {
        // 可以在这里处理作业的释放逻辑
    }
}
